/**
 * @file wdt.c
 * @brief T1 Watchdog Driver
 *
 * @author yemt@witsi.cn
 * @date 2011-10-15
 * @version T1.WDT.01
 */
#include "regs.h"
#include "ictl.h"
#include "wdt.h"
#include "dev.h"
#include "init.h"

/**
 * @fn watchdog_irq
 * @brief Watchdog Interrupt Handler
 *
 * @return void
 */
static void watchdog_irq(void)
{
        WDT->WDT_ICLR = WDT->WDT_RIS;
        return;
}

/**
 * @fn watchdog_init
 * @brief Watchdog Initializer
 *
 * @return 0
 */
static int watchdog_init(void)
{
        WDT->WDT_LOCK = 0x1ACCE551;
        WDT->WDT_CTL = 0;
        WDT->WDT_ICLR = 0x01;
        request_irq(IRQ_WDT, watchdog_irq);
        return 0;
}

arch_initcall(watchdog_init);

/**
 * @fn watchdog_enable
 * @brief Watchdog Enable
 *
 * @param value         Watchdog Load Value
 * @return 0
 */
void watchdog_enable(uint32_t value)
{
        WDT->WDT_LOAD = value;
        WDT->WDT_CTL = 0x03;
}
